package com.spsoft.core.controller;

import com.spsoft.core.model.bo.TokenUser;
import com.spsoft.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 所有controller的基类，据说可以方便扩展
 * description: BaseController <br>
 * date: 2021-4-19 11:21 <br>
 * author: zjh <br>
 * version: 1.0 <br>
 */
public class BaseController {
    @Autowired(required = false)
    protected HttpServletRequest request;
    @Autowired(required = false)
    protected HttpServletResponse response;


    /**
     * 获取用户名
     *
     * @return {@link String}
     */
    protected String getUserName( ) {
        return SecurityUtils.getUsername();
    }

    /**
     * 获取当前登录用户信息
     *
     * @return {@link TokenUser}
     */
    protected TokenUser getUser() {
        return SecurityUtils.getTokenUser();
    }

    /**
     * 获取机构代码
     *
     * @return {@link String}
     */
    protected String getDeptCode( ) {
        return SecurityUtils.getDeptCode();
    }
}
